const path = require('path');
const Strip = require('strip-loader');

module.exports = function (env) {

    const dev = env.dev;


    return {
        mode: dev ? 'development' : 'production',
        entry: dev ? ['@babel/polyfill','./src/index.js'] : './src/axios.js',
        output: {
            path: path.resolve(__dirname, 'dist'),
            filename: dev ? 'axios.js' : 'axios.min.js',
            sourceMapFilename: dev ? 'axios.map' : 'axios.min.map',
            libraryTarget:'umd'
        },
        devtool:'source-map',
        devServer:{
            //contentBase:'./dist',
            port:8080,
            open:true
        },
        module:{
            rules:[
                {
                    test:/\.js$/,
                    use:[
                        {
                            loader:'babel-loader',
                            options:{
                                presets:['@babel/preset-env']
                            }
                        },

                        //去除冗余代码
                        // {
                        //     loader:Strip.loader('alert','assert')
                        // }
                    ]
                }
            ]
        }

    }
}